package com.zc.springmvc.servlet.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zc.springmvc.busniess.service.Iuser;
import com.zc.springmvc.mybatis.bean.UserBean;
import com.zc.springmvc.mybatis.bean.UserLoginFrom;
import com.zc.springmvc.tool.JsonHelper;

@Controller
public class UserHandler {

	@Autowired
	private Iuser iuser;

	@RequestMapping(value = "/register")//method = RequestMethod.POST
	public ResponseEntity<String> register(HttpServletRequest request,
			HttpServletResponse response, @Param("user") UserBean userbean,
			Model model) {
		HttpStatus statusCode = null;
		try {
//			iuser.insertUser(userbean);
			statusCode = HttpStatus.OK;
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = HttpStatus.BAD_REQUEST;
		}

		return new ResponseEntity<String>(JsonHelper.buildJsonString(userbean),
				JsonHelper.buildJsonHeaders(), statusCode);
	}

	@RequestMapping(value = "/login")
	public String login(HttpServletRequest request,
			HttpServletResponse response,
			@Param("user") UserLoginFrom userLogin, Model model) {
		String pwd = userLogin.getPwd();
		if (pwd == null || "".equals(pwd.trim())) {

		}
		return null;
	}
}
